package com.tc.config;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.core.TopicExchange;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.HashMap;
import java.util.Map;

@Configuration
public class RabbitMQConfig {
    @Bean
    public Queue orderwait(){ return new Queue("orderwait-queue",true,false,false);}

    @Bean
    public TopicExchange orderWaitExchange(){
        return new TopicExchange("orderwait-exchange",true,false);
    }

    @Bean
    public Binding bingdingOrderwaitQueue(){
        return BindingBuilder.bind(orderwait()).to(orderWaitExchange()).with("orderwait.#");
    }

    @Bean
    public Queue orderQueue(){
        return new Queue("order-queue",true,false,false);
    }

    @Bean
    public TopicExchange orderExchange(){
        return new TopicExchange("order-exchange",true,false);
    }

    @Bean
    public Binding bindingOrderQueue(){
        return BindingBuilder.bind(orderQueue()).to(orderExchange()).with("order.#");
    }

    //单独创建一个交换机，存储order数据
    @Bean
    public TopicExchange payExchange(){
        return new TopicExchange("pay-exchange",true,false);
    }

    @Bean
    public Queue payQueue(){
        Map params = new HashMap<>();
        params.put("x-message-ttl",10000);
        params.put("x-dead-letter-exchange","dlx-pay-exchange");
        params.put("x-dead-letter-routing-key","pay.order");
        return new Queue("pay-queue",true,false,false,params);
    }

    @Bean
    public Binding bindPayQueue(){
        return BindingBuilder.bind(payQueue()).to(payExchange()).with("pay.#");
    }

    @Bean
    public TopicExchange dlxPayExchange(){
        return new TopicExchange("dlx-pay-exchange",true,false);
    }

    @Bean
    public Queue dlqPayQueue(){
        return new Queue("dlq-pay-queue",true,false,false);
    }

    @Bean
    public Binding bingPayQueue(){
        return  BindingBuilder.bind(dlqPayQueue()).to(dlxPayExchange()).with("pay.order");
    }












}
